import Vue from 'vue'
import App from './App.vue'
import './plugins/element.js'
import router from './router'

Vue.config.productionTip = false

import http from './http'
Vue.prototype.$http = http


Vue.mixin({
  computed:{
    uploadUrl(){
      return this.$http.defaults.baseURL + '/upload'
    }
  },
  methods:{
    getAuthHeaders(){
      return {
        Authorization : `Bearer ${sessionStorage.token || ''}`
      }
    }
  }
})
//  根据token以及跳转的路径来判断，这个需要重定位；只要登陆了就不能在进入登陆页面，只要未登陆进不去别的页面；输入/直接进入设定好的页面
router.beforeEach((to, from, next) => {
  if(sessionStorage.token  && to.name == 'Login'){
     next('/heroes/create')
  }else{
    next()
  }

})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
